home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware in MacFormat / LogicSim 2.1 ƒ / LogicSim SDK / MyProc ƒ / MyProc.p < prev    next >
Encoding:
Text File  |  1995-03-15  |  1.8 KB  |  105 lines  |  [TEXT/MWPS]

  1. unit MyProc;
  2.  
  3. interface
  4.  
  5.     uses
  6.         LSInterface;
  7.  
  8. {$MAIN}
  9.     procedure proc (var blk: LSBlock);
  10.  
  11. implementation
  12.  
  13.     function SetCurrentA4: longint; C;
  14.  
  15.     {the linker doesn't want to find SetA4 (why?) so I copy it here}
  16.     function SetA4 (newA4: longint) : longint; ASM;
  17.     begin
  18.         move.l    4(a7),d0
  19.         exg        d0,a4
  20.         move.l    d0,8(a7)
  21.         move.l    (a7)+,(a7)
  22.         rts
  23.     end;
  24.  
  25.  
  26.  
  27.  
  28.     const
  29.         CLASSNAME = 'MyProc';
  30.         PICTID = 128;
  31.  
  32.     type
  33.         ClassDatasRec = record
  34.                 pic: PicHandle;
  35.             end;
  36.         ClassDatasP = ^ClassDatasRec;
  37.         ClassDatasH = ^ClassDatasP;
  38.  
  39.     procedure DoNewClass (var blk: LSBlock);
  40.         var
  41.             h: Handle;
  42.             err: OSErr;
  43.     begin
  44.         blk.prm.prmClass^.name := CLASSNAME;
  45.         h := GetResource('PICT', PICTID);
  46.         HNoPurge(h); DetachResource(h);
  47.         blk.prm.prmClass^.image := Pointer(h);
  48.         SetClassID(blk.prm.prmClass^.id, CLASSNAME);
  49.  
  50.         LSDeclarePin(blk.env, blk.classRef, Pnt(0,5), kInputPin, 'in1');
  51.         LSDeclarePin(blk.env, blk.classRef, Pnt(0,15), kInputPin, 'in2');
  52.         LSDeclarePin(blk.env, blk.classRef, Pnt(50,10), kOutputPin, 'out');
  53.  
  54.         SetHandleSize(Handle(blk.classDatas), sizeof(ClassDatasRec));
  55.         err := HandToHand(h);
  56.         ClassDatasH(blk.classDatas)^^.pic := Pointer(h);
  57.     end;
  58.  
  59.  
  60.     procedure DoDraw (var blk: LSBlock);
  61.     begin
  62.         DrawPicture(ClassDatasH(blk.classDatas)^^.pic, blk.prm.prmItem^.frame);
  63.     end;
  64.  
  65.     procedure DoSimulation (var blk: LSBlock);
  66.         var
  67.             in1, in2, out: XBool;
  68.     begin
  69.         LSGetInput(blk.env, blk.gateRef, 1, in1);
  70.         LSGetInput(blk.env, blk.gateRef, 2, in2);
  71.         out := _AND(in1, in2);
  72.         LSSetOutput(blk.env, blk.gateRef, 3, out);
  73.     end;
  74.  
  75.  
  76.  
  77.  
  78.     procedure proc (var blk: LSBlock);
  79.         var
  80.             oldA4: longint;
  81.     begin
  82.  
  83.         oldA4 := SetCurrentA4;
  84.         
  85.         case blk.msg of
  86.  
  87.             msgNewClass: 
  88.                 DoNewClass(blk);
  89.  
  90.             msgDisposeClass: 
  91.                 DisposeHandle(Handle(ClassDatasH(blk.classDatas)^^.pic));
  92.  
  93.             msgDraw: 
  94.                 DoDraw(blk);
  95.  
  96.             msgSimulation: 
  97.                 DoSimulation(blk);
  98.  
  99.         end;
  100.  
  101.         oldA4 := SetA4(oldA4);
  102.     end;
  103.  
  104.  
  105. end.